package com.meirengu.channel.service.impl;

import com.meirengu.channel.service.R360Service;
import com.meirengu.utils.HttpUtil;
import com.meirengu.utils.MD5Util;
import com.meirengu.utils.RequestUtil;
import com.meirengu.webview.utils.ConfigUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 360借条接口
 *
 * @author Mao
 * @create 2017-12-15 12:11
 */
@Service
public class R360ServiceImpl implements R360Service {

    Logger logger = LoggerFactory.getLogger(R360ServiceImpl.class);

    @Override
    public void check(HttpServletRequest request, String name, String phone, String amount) {
        String ip = RequestUtil.getClientIp(request);
        String url = ConfigUtil.getConfig("r360.check.url");
        String partnerName = ConfigUtil.getConfig("");
        String c = ConfigUtil.getConfig("");
        String key = ConfigUtil.getConfig("");
        Map<String, String> params = new HashMap<>();
        params.put("PartnerName", partnerName);
        params.put("c", c);
        params.put("Name", name);
        params.put("Phone", phone);
        params.put("IP", ip);
        params.put("LoanAmount", amount);
        params.put("token", MD5Util.get32MD5(phone + c + key));
        HttpUtil.HttpResult hr = HttpUtil.doPostForm(url, params);
        int code = hr.getStatusCode();
        if (code == 200) {

        } else {
            logger.warn("==R360ServiceImpl.check request fail. code:{}, result:{}", code, hr.toString());
        }
    }
}
